package com.mike.eventdriven;

import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;

/**
 * Hello world!
 */
public class App extends JFrame {
    private JButton but;

    public App() throws HeadlessException, InvocationTargetException, InterruptedException {
        this.but = but;
        but = new JButton("确定");
        but.setBounds(250, 180, 70, 20);
        but.addActionListener(new MyListener());
        this.add(but);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(600, 400);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        TimeUnit.SECONDS.sleep(5);
//        SwingUtilities.invokeAndWait(new Runnable() {
//            @Override
//            public void run() {
//                but.doClick();
//            }
//        });
        but.doClick();
    }

    public static void main(String[] args) throws InvocationTargetException, InterruptedException {
        new App();
    }
}
